bitkeeper revision 1.637 (3fca7701y4KoOnx1zp_ccoR7G153xg)
authoriap10@labyrinth.cl.cam.ac.uk <iap10@labyrinth.cl.cam.ac.uk>
Sun, 30 Nov 2003 23:02:25 +0000 (23:02 +0000)
committeriap10@labyrinth.cl.cam.ac.uk <iap10@labyrinth.cl.cam.ac.uk>
Sun, 30 Nov 2003 23:02:25 +0000 (23:02 +0000)
Add dom0 op to pin a domain to a specified CPU (or -1 to unpin).
This function is currently only supported for domains that have
been 'created' but not 'built' or 'started'.

.rootkeys
BitKeeper/etc/ignore
tools/examples/pincpu.py [new file with mode: 0755]
tools/xc/lib/xc_domain.c
tools/xc/py/Xc.c
tools/xc/py/XenoUtil.py
xen/common/dom0_ops.c
xen/include/hypervisor-ifs/dom0_ops.h
xen/include/xeno/sched.h

index 4e135eadd2b60cda9cd54236f2594fa16082fb23..fe17b6d2ab31f2b9e1d9202efb1531bdf6e82eee 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
@@ -42,6 +42,7 @@
 3fbe2f12OPAkzIUtumU3wRAihnhocQ tools/examples/createlinuxdom.py
 3fbe2f12dZbmXLlgQdMgkmnSUj23AQ tools/examples/destroydom.py
 3fbe2f12ltvweb13kBSsxqzZDAq4sg tools/examples/listdoms.py
+3fca7700PVj36cZObaFZlQicRiw1pQ tools/examples/pincpu.py
 3fbe2f12Bnt8mwmr1ZCP6HWGS6yvYw tools/examples/stopdom.py
 3f776bd2Xd-dUcPKlPN2vG89VGtfvQ tools/misc/Makefile
 3f6dc136ZKOjd8PIqLbFBl_v-rnkGg tools/misc/miniterm/Makefile
index d68573efe9b7d6a4efd3d4be9f1627bebc8b8421..8ceb5a914c3e34762fdfcb4a62663940e03c9f62 100644 (file)
@@ -513,3 +513,13 @@ xen/drivers/scsi/aic7xxx/aic79xx_osm.o
 xen/drivers/scsi/aic7xxx/aic79xx_osm_pci.o
 xen/drivers/scsi/aic7xxx/aic79xx_pci.o
 xen/drivers/scsi/aic7xxx/aic79xx_proc.o
+tools/xc/lib/xc_bvtsched.o
+tools/xc/lib/xc_domain.o
+tools/xc/lib/xc_linux_build.o
+tools/xc/lib/xc_linux_restore.o
+tools/xc/lib/xc_linux_save.o
+tools/xc/lib/xc_misc.o
+tools/xc/lib/xc_private.o
+tools/xc/lib/xc_vbd.o
+tools/xc/lib/xc_vif.o
+xen/xen.s
diff --git a/tools/examples/pincpu.py b/tools/examples/pincpu.py
new file mode 100755 (executable)
index 0000000..d978067
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+#
+# Destroy specified domain.
+#
+
+import Xc, sys, re
+
+xc = Xc.new()
+
+if len(sys.argv) < 3:
+    print "Specify a domain identifier and CPU"
+    sys.exit()
+
+xc.domain_pincpu( dom=int(sys.argv[1]), cpu=int(sys.argv[2]))
+
index f120791848658ab001b21bbe50dc227767e4dd3f..5601fb485cd3b48911b76535138d2c2c01f5e804 100644 (file)
@@ -57,6 +57,18 @@ int xc_domain_destroy(int xc_handle,
     return do_dom0_op(xc_handle, &op);
 }
 
+int xc_domain_pincpu(int xc_handle,
+                      unsigned int domid, 
+                      int cpu)
+{
+    dom0_op_t op;
+    op.cmd = DOM0_PINCPUDOMAIN;
+    op.u.pincpudomain.domain = domid;
+    op.u.pincpudomain.cpu  = cpu;
+    return do_dom0_op(xc_handle, &op);
+}
+
+
 int xc_domain_getinfo(int xc_handle,
                       unsigned int first_domid,
                       unsigned int max_doms,
index 05309b5daf995a9bee1d55872109237fcecd5508..0676bd137b9a15f7d6bbcee8c4fd595c0f0b8123 100644 (file)
@@ -95,6 +95,26 @@ static PyObject *pyxc_domain_destroy(PyObject *self,
     return PyInt_FromLong(ret);
 }
 
+static PyObject *pyxc_domain_pincpu(PyObject *self,
+                                     PyObject *args,
+                                     PyObject *kwds)
+{
+    XcObject *xc = (XcObject *)self;
+
+    unsigned int dom;
+    int cpu, ret;
+
+    static char *kwd_list[] = { "dom", "cpu", NULL };
+
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list, 
+                                      &dom, &cpu) )
+        return NULL;
+
+    ret = xc_domain_pincpu(xc->xc_handle, dom, cpu);
+    
+    return PyInt_FromLong(ret);
+}
+
 static PyObject *pyxc_domain_getinfo(PyObject *self,
                                      PyObject *args,
                                      PyObject *kwds)
@@ -507,6 +527,14 @@ static PyMethodDef pyxc_methods[] = {
       " force [int, 0]: Bool - force immediate destruction?\n\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
+    { "domain_pincpu", 
+      (PyCFunction)pyxc_domain_pincpu, 
+      METH_VARARGS | METH_KEYWORDS, "\n"
+      "Pin a domain to a specified CPU.\n"
+      " dom   [int]:    Identifier of domain to be destroyed.\n"
+      " force [int, -1]: CPU to pin to, or -1 to unpin\n\n"
+      "Returns: [int] 0 on success; -1 on error.\n" },
+
     { "domain_getinfo", 
       (PyCFunction)pyxc_domain_getinfo, 
       METH_VARARGS | METH_KEYWORDS, "\n"
index 1a135bfdffb4526c0114ca680941236049b0f58a..dfbcabc800c2e0fcf96663233ac441abbdf8dba1 100644 (file)
@@ -128,3 +128,17 @@ def setup_vfr_rules_for_vif(dom,vif,addr):
               ' proto=any\n' )
     os.close( fd )
     return None
+
+def addr_of_iface( iface ):
+    fd = os.popen( '/sbin/ifconfig '+iface )
+    lines = fd.readlines()
+    for line in lines:
+       m = re.search( 'inet addr:([0-9.]+)', line )
+       if m: 
+           return m.group(1)
+    return None
+
+def add_to_ip( ip, off ):
+    l = string.split(ip,'.')
+    return '%s.%s.%s.%d' % ( l[0],l[1],l[2],string.atoi(l[3])+off )
+
index 344a65f83a906d6eee3ac21ccd2d17c1b3bdbcaf..5f5e803c5a8a26b320085dfefc3807878fbb63bd 100644 (file)
@@ -184,6 +184,39 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
     }
     break;
 
+    case DOM0_PINCPUDOMAIN:
+    {
+        struct task_struct * p = find_domain_by_id(op.u.pincpudomain.domain);
+       int cpu = op.u.pincpudomain.cpu;
+        ret = -EINVAL;
+        if ( p != NULL )
+        {
+           if( cpu == -1 )
+             p->cpupinned = 0;
+           else
+             {
+               /* For the moment, we are unable to move running
+               domains between CPUs. (We need a way of cleanly stopping 
+               running domains). For now, if we discover the domain is
+               running then cowardly bail out with ENOSYS */
+
+               if(p->flags & PF_CONSTRUCTED) 
+                 ret = -ENOSYS;
+               else
+                 {
+                   cpu = cpu % smp_num_cpus;
+                   p->processor = cpu;
+                   p->cpupinned = 1;
+                 }
+             }
+
+           ret = 0;
+            put_task_struct(p);
+        }
+       
+    }
+    break;
+
     case DOM0_BVTCTL:
     {
         unsigned long  ctx_allow = op.u.bvtctl.ctx_allow;
index 2c3d12ab78b04de81a81fc38184058463bd9be02..045e4ad70e35dfb26402db0d14e7e94284ccf5f4 100644 (file)
@@ -197,6 +197,17 @@ typedef struct dom0_readconsole_st
     unsigned int cmd;
 } dom0_readconsole_t;
 
+/* 
+ * Pin Domain to a particular CPU  (use -1 to unpin)
+ */
+#define DOM0_PINCPUDOMAIN     20
+typedef struct dom0_pincpudomain_st
+{
+    /* IN variables. */
+    unsigned int domain;
+    int          cpu;  /* -1 implies unpin */
+} dom0_pincpudomain_t;
+
 typedef struct dom0_op_st
 {
     unsigned long cmd;
@@ -218,7 +229,12 @@ typedef struct dom0_op_st
        dom0_debug_t            debug;
        dom0_settime_t          settime;
        dom0_readconsole_t      readconsole;
+       dom0_pincpudomain_t     pincpudomain;
     } u;
 } dom0_op_t;
 
+
+
+
+
 #endif
index b4a7520a64961e54cc9e71cbe42d5b862a6e46ea..736201446a5227f73801cc73cd3e07ca1e905267 100644 (file)
@@ -102,7 +102,8 @@ struct task_struct
     struct list_head run_list;
     int              has_cpu;
     int state;                  /* current run state */
-    
+    int cpupinned;              /* true if pinned to curent CPU */
+
     s_time_t lastschd;              /* time this domain was last scheduled */
     s_time_t cpu_time;              /* total CPU time received till now */
     s_time_t wokenup;               /* time domain got woken up */